package com.itcast.springboot.waste_recovery.controller;


import com.itcast.springboot.waste_recovery.common.CommonResult;
import com.itcast.springboot.waste_recovery.common.CommonResultCode;
import com.itcast.springboot.waste_recovery.domain.Withdrawal;
import com.itcast.springboot.waste_recovery.service.WithdrawalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 提现表 前端控制器
 * </p>
 *
 * @author 小破烂
 * @since 2020-08-23
 */
@RestController
@RequestMapping("/waste_recovery/withdrawal")
@Api(tags = "提现表类接口")
public class WithdrawalController {
    @Resource(name = "withdrawalServiceImpl")
    WithdrawalService withdrawalService;


    @PostMapping("/customer/{user_id}/{withdrawal_amount}")
    @ApiOperation(value = "用户端：提现")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_id", value = "用户id"),
            @ApiImplicitParam(name = "withdrawal_amount", value = "提现金额：元")
    })
    @RequiresPermissions("user-operated")       //拥有 user-operated 才可以访问
    public CommonResult Withdrawal(@PathVariable(value = "user_id") Integer userId,
                                   @PathVariable(value = "withdrawal_amount") Float withdrawalAmount){

        Integer result = withdrawalService.Withdrawal(userId, withdrawalAmount);
        if (result <= 0){
            return CommonResult.CommonFail();
        }
        return new CommonResult(CommonResultCode.CommonSuccess, result);
    }
}

